﻿
// ExeDlg.cpp: 实现文件


#include "pch.h"
#include "framework.h"
#include "Exe.h"
#include "ExeDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CExeDlg::CExeDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_EXE_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CExeDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    // TODO: Add your control variable mappings here
    DDX_Control(pDX, IDC_EDIT1, m_editBox1);
    DDX_Control(pDX, IDC_EDIT2, m_editBox2);
}

BEGIN_MESSAGE_MAP(CExeDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON_SHOW1, &CExeDlg::OnBnClickedShow1)
    ON_BN_CLICKED(IDC_BUTTON_CLEAR1, &CExeDlg::OnBnClickedClear1)
    ON_BN_CLICKED(IDC_BUTTON_SHOW2, &CExeDlg::OnBnClickedShow2)
    ON_BN_CLICKED(IDC_BUTTON_CLEAR2, &CExeDlg::OnBnClickedClear2)
    ON_BN_CLICKED(IDC_BUTTON_COPYTORIGHT, &CExeDlg::OnBnClickedCopyToRight)
END_MESSAGE_MAP()

// CExeDlg message handlers

BOOL CExeDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    return TRUE;  // return TRUE unless you set the focus to a control
}

void CExeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CDialogEx aboutDlg(IDD_ABOUTBOX);
        aboutDlg.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}

void CExeDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}

HCURSOR CExeDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}

void CExeDlg::OnBnClickedShow1()
{
    m_editBox1.SetWindowText(_T("哈哈哈！！！"));
}

void CExeDlg::OnBnClickedClear1()
{
    m_editBox1.SetWindowText(_T(""));
}

void CExeDlg::OnBnClickedShow2()
{
    m_editBox2.SetWindowText(_T("呵呵呵！！！"));
}

void CExeDlg::OnBnClickedClear2()
{
    m_editBox2.SetWindowText(_T(""));
}

void CExeDlg::OnBnClickedCopyToRight()
{
    CString str;
    m_editBox1.GetWindowText(str);
    m_editBox2.SetWindowText(str);
}

void CExeDlg::OnBnClickedButtonExit()
{
    //关闭当前对话框
    EndDialog(0); 
}
